<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Details du fournisseur</title>


<!---------------------for autocomplete--------------->
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-1.11.0.min.js');?>" ></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-ui-1.10.4/js/jquery-ui-1.10.4.min.js');?>" ></script>
	<link href="<?php echo base_url("assets/css/jquery-ui.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form css ----------------------->
	<link href="<?php echo base_url("assets/css/pure.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form validation ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.validate.js');?>" ></script>
<!---------------------for form mask input ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.mask.min.js');?>" ></script>


</head>
<body>
<?php
include_once('header.php');
$r1=$fournisseur['rec'];  // one fournisseur
$r2=$liste_fourn['rec'];  // list of all fournisseur for autocomplete
$r3=$liste_activite['rec']; // list of all activities for auto complete
$r4=$activite['rec']; // one activity for one fournisseur
$r5=$liste_bank['rec']; // list of banks for one fournisseur 

// ----- populate $liste_des_fournisseurs array for autocomplete ----- //
$liste_des_fournisseurs = array();
foreach ($r2 as $lf){
	array_push($liste_des_fournisseurs, $lf->nom);
}
// ----- populate $liste_des_activites array for autocomplete ----- //
$liste_des_activites = array();
foreach ($r3 as $lda){
	array_push($liste_des_activites, $lda->titre);
	
}
?>


<form id="fournisseur_frm" class="pure-form pure-form-stacked" action="<?php echo base_url('fournisseur_ctr/update');?>">
    <fieldset>
        <legend>تفاصيل المورد رفم: <?php echo('<strong>'.$r1[0]->id_fournisseur.'</strong>');?></legend>

        <div class="pure-g">
            <div class="pure-u-1 pure-u-md-1-3">
                <label for="nom">الاسم </label>
				<input id="nom" type="text" value="<?php echo($r1[0]->nom);?>">
            </div>

            <div class="pure-u-1 pure-u-md-1-3 ">
                <label for="phone">الهاتف </label>
                <input  class="ltr" id="phone" type="text" value="<?php echo($r1[0]->tel);?>">
            </div>

            <div class="pure-u-1 pure-u-md-1-3 ">
                <label for="mobile"> النقال </label>
				<input class="ltr" id="mobile" type="text" value="<?php echo($r1[0]->tel_mob);?>">
                <!--<input id="email" type="email" >-->
            </div>

            <div class="pure-u-1 pure-u-md-1-3 ">
                <label for="fax">الفاكس </label>
                <input class="ltr" id="fax" type="text" value="<?php echo($r1[0]->fax);?>">
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3">
                <label for="address">العنوان  </label>
                <input id="address" type="text" value="<?php echo($r1[0]->adresse);?>">
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3">
                <label for="rc"> السجل التجاري/autre  </label>
                <input  class="ltr" id="rc" type="text"  placeholder="00/00-00000(0000)A00" value="<?php echo($r1[0]->rc);?>">
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3">
                <label for="rib"> تفاصيل البنك  </label>
                <input   class="ltr" style="width: 225px;" id="rib" type="text" value="<?php echo('rrrrrrrrrrrrr');?>">
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3">
                <label for="type_activit">  طبيعة النشاط</label>
                <input id="type_activit" type="text" value="<?php echo($r4[0]->titre);?>">
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3">
                <label for="email"> البريد الإلكتروني  </label>
                <input  class="ltr" id="email" type="email" value="<?php echo($r1[0]->email);?>">
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3">
                <label for="contact">  نقطة الإتصال  </label>
                <input id="contact" type="text" value="<?php echo($r1[0]->contact);?>">
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3">
                <label for="notes">  ملاحظات  </label>
                <textarea id='notes' rows="4" cols="50" > <?php echo($r1[0]->comments);?> </textarea>  
            </div>
			
        </div>

      

        <button type="submit" id="submit_btn" class="pure-button pure-button-primary">تحديث</button>
    </fieldset>
</form>


</body>
<script>
$(function() {
	

var liste_fourniss = <?php echo json_encode($liste_des_fournisseurs); ?>;
var liste_activites = <?php echo json_encode($liste_des_activites); ?>;

$( "#nom" ).autocomplete({source: liste_fourniss});
$( "#type_activit" ).autocomplete({source: liste_activites});


});

//---

$('#submit_btn').click(function() {
  if($("[class^=error]").is(":visible")){
    alert('منالك حقل / حقول إدخال غير مطابقة !');
    return false;
  } else {
  	$('#fournisseur_frm').submit();
    return false;
  }
});


$('#rc').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-rc').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    //var characterReg = /^([a-zA-Z0-9]{7,16})$/;
    var characterReg = /^([0-9]{2}\/[0-9]{2}-[0-9]{5,9}[a-zA-Z][0-9]{2})$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-rc" flag="required" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});

//---
$('#rib').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-rib').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    var characterReg = /^(\d{3}-\d{5}-\d{10}-\d{2})$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-rib" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});

$('#phone').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-phone').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    var characterReg = /^(\(\d{3}\)-\d{2}-\d{2}-\d{2})$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-phone" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});

$('#mobile').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-mobile').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    var characterReg = /^(\(\d{4}\)-\d{2}-\d{2}-\d{2})$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-mobile" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});
/*
$('#email').bind('mouseup keyup focusout focus mousemove',function() {
    $('span.error-email').hide();
	$(this).css('background-color','pink');
    var inputVal = $(this).val();
    var characterReg = /^(\b[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b)$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('<span class="error-email" style="color:red;" >حقل غير مطابق للشكل العام </span>');
    }else{
		$(this).css('background-color','#FFFFFF');
	}
});
*/


//---* maskage below 
$('#rc').mask('AA/AA-AAAAAOOOODAA', {'translation': {
                                        A: {pattern: /[0-9]/},
										O: {pattern: /[0-9]/, optional: true},
										D: {pattern: /[a-zA-Z]/}
                                      }
                                });

$('#rib').mask('000-00000-0000000000-00');
$('#phone').mask('(A00)-00-00-00',{'translation': { A: {pattern: /[0]/} } });
$('#mobile').mask('(AB00)-00-00-00',{'translation': { A: {pattern: /[0]/},B: {pattern: /[5,6,7]/} } }); // nedjma djeezy et mobilis 							
$('#fax').mask('(A00)-00-00-00',{'translation': { A: {pattern: /[0]/} } });



</script>
</html>